package com.frinder.base.global;

/**
 * @ClassName BaseException
 * @Author frinder
 * @Description 自定义异常类
 * @Date 2019/1/19 15:18
 * @Version 1.0
 */
public class BaseException extends RuntimeException {

    public enum Code {

        SYSTEM_ERROR(10000, "系统错误！"),
        MORE_THAN_ONE(20001, "查询结果只应该有一个，却查询出多个！"),
        SAVE_FAIL(20001, "保存失败！"),
        UPDATE_FAIL(20003, "更新失败！"),
        DELETE_FAIL(20004, "删除失败！"),
        EXPECT_RECORD_NOT_EXISTS(30001, "期望记录不存在！"),
        CALL_SERVICE_ERROR(40001, "调用第三方服务失败！");

        private final int code;
        private final String message;

        public int getCode() {
            return code;
        }

        public String getMessage() {
            return message;
        }

        Code(int code, String message) {
            this.code = code;
            this.message = message;
        }
    }

    private Code code;

    public BaseException(Code code) {
        super(code.message);
        this.code = code;
    }

    public BaseException(String message, Code code) {
        super(message);
        this.code = code;
    }

    public Code getCode() {
        return code;
    }

    public void setCode(Code code) {
        this.code = code;
    }
}
